package com.keldian.mobilesafe.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.keldian.mobilesafe.R;
import com.keldian.mobilesafe.ui.DialogEnterPwd;
import com.keldian.mobilesafe.ui.DialogSetPwd;
import com.keldian.mobilesafe.utils.SharePrefenceTool;

/**
 * Created by Administrator on 15-12-7.
 */
public class HomeActivity extends Activity {
    private GridView list_home;
    private MyAdapter adapter;
    private static String[] names = {
            "手机防盗", "通讯卫士", "软件管理",
            "进程管理", "流量统计", "手机杀毒",
            "缓存清理", "高级工具", "设置中心"

    };


    private static int[] ids = {
            R.drawable.safe, R.drawable.callmsgsafe, R.drawable.app,
            R.drawable.taskmanager, R.drawable.netmanager, R.drawable.trojan,
            R.drawable.sysoptimize, R.drawable.atools, R.drawable.settings

    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);


        setContentView(R.layout.activity_home);
        list_home = (GridView) findViewById(R.id.list_home);
        adapter = new MyAdapter();
        list_home.setAdapter(adapter);
        list_home.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                switch (position) {

                    case 0:
                        showLostFindDialog();
                        break;

                    case 1://加载黑名单拦截界面
                        Intent intent1 = new Intent(HomeActivity.this, CallSmsSafeActivity.class);
                        startActivity(intent1);
                        break;

                    case 2://软件管理器
                        Intent intent2 = new Intent(HomeActivity.this, AppManagerActivity.class);
                        startActivity(intent2);
                        break;

                    case 3://进程管理器
                        Intent intent3 = new Intent(HomeActivity.this, TaskManagerActivity.class);
                        startActivity(intent3);
                        break;

                    case 4://流量统计
                        Intent intent4 = new Intent(HomeActivity.this, TrafficManagerActivity.class);
                        startActivity(intent4);
                        break;

                    case 5://手机杀毒
                        Intent intent5 = new Intent(HomeActivity.this, AntiVirusActivity.class);
                        startActivity(intent5);
                        break;

                    case 6://缓存清理
                        Intent intent6 = new Intent(HomeActivity.this, CleanCacheActivity.class);
                        startActivity(intent6);
                        break;

                    case 7://进入高级工具
                        Intent intents = new Intent(HomeActivity.this, AtoolsActivity.class);
                        startActivity(intents);
                        break;

                    case 8://进入设置中心
                        Intent intent = new Intent(HomeActivity.this, SettingActivity.class);
                        startActivity(intent);

                        break;
                    default:
                        break;
                }

            }
        });
    }

    private void showLostFindDialog() {
        if (isSetPwd()) {
            //已设置密码，弹出输入密码提示框
            showEnterDialog();
        } else {
            showSetPwdDialog();
        }

    }

    private void showSetPwdDialog() {
        DialogSetPwd dialogEnterPwd = new DialogSetPwd(HomeActivity.this);
    }

    private void showEnterDialog() {
        DialogEnterPwd dialogEnterPwd = new DialogEnterPwd(HomeActivity.this);
    }

    public boolean isSetPwd() {
        if (TextUtils.isEmpty(SharePrefenceTool.getFDPwd(this))) {
            return false;
        }
        return true;
    }


    private class MyAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return names.length;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            View view = View.inflate(HomeActivity.this, R.layout.list_item_home, null);
            ImageView iv_item = (ImageView) view.findViewById(R.id.iv_item);
            TextView tv_item = (TextView) view.findViewById(R.id.tv_item);

            tv_item.setText(names[position]);
            iv_item.setImageResource(ids[position]);
            return view;
        }

        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return 0;
        }


    }
}
